package com.wsj.web.action.admin.file;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class ImagesDelAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		String[] file_name_array = request.getParameterValues("xxx");
		this.delImgFile(file_name_array);
		return mapping.findForward("success");
	}
	
	private void delImgFile(String[] args){
		if(args!=null && args.length!=0){		
			String basePath = this.getServlet().getServletContext().getRealPath(File.separator);
			File file = null;
			for(int i=0;i<args.length;i++){
				String img_file_name = args[i].trim();
				file = new File(basePath+img_file_name);
				if(file.exists() && file.isFile()){
					file.delete();
				}
			}	
		}else{	
		}	
	}

}
